
package com.ls.fw.mvc.struts.converter;

import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

import com.ls.fw.commons.core.log.PlatLogger;

public class IntegerTypeConverter extends StrutsTypeConverter{
    private static final PlatLogger LOG = new PlatLogger(IntegerTypeConverter.class);

    @Override
    public Object convertFromString(Map context, String[] values, Class toClass) {
        if (values[0] == null || values[0].trim().equals("")) {
            return 0;
        }
        try{
            return Integer.parseInt(values[0].trim());
        }catch(Exception e){
            LOG.info("字符串:"+values[0].trim()+"转换为数字失败");
        }
        return 0;
    }
    @Override
    public String convertToString(Map context, Object o) {
        if (o == null) {
            return "0";
        }
        return o.toString();
    }
}